#!/bin/sh

set -e

if [ $# -eq 3 ] || [ $# -eq 4 ]; then
	kernelversion="$1"
	bootimage="$2"
	mapfile="$3"
	destdir="${4:-/boot}"
else
	echo "Usage: installkernel <version> <image> <System.map> <directory>"
	exit 1
fi


mapdir=$(dirname "$mapfile")
config="$mapdir"/.config


suffix=
flavor=${kernelversion##*[0-9]-}
if [ "$flavor" != "$kernelversion" ]; then
	suffix=-$flavor
fi

for i in vmlinuz${suffix} System.map${suffix} config${suffix}; do
	if [ -e "$destdir"/$i ]; then
		cp "$destdir"/$i "$destdir"/$i.old
	fi
done

cp "$bootimage" "$destdir"/vmlinuz${suffix}
cp "$mapfile" "$destdir"/System.map${suffix}
cp "$config" "$destdir"/config${suffix}

exit 0
